<template>
  <div>
    <div class="bigbox">
      <el-table
        :data="
          tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
        "
        border
        style="width: 100%"
      >
        <el-table-column prop="name" label="商品名称" width="300">
        </el-table-column>
        <el-table-column prop="price" label="商品价格" width="300">
        </el-table-column>
        <el-table-column prop="operate" label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="reducebt(scope.$index, scope.row)"
              >下架</el-button
            ><el-button
              size="mini"
              type="danger"
              @click="addbt(scope.$index, scope.row)"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页器 -->
    <el-pagination
      align="center"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.length"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      currentPage: 1, //当前数据页
      pageSize: 5, //每页条数
      num: 0,
    };
  },
  created() {
    // 接收来自vuex的数据
    console.log(this.tableData);
    this.tableData = this.$store.state.newtableData;
  },
  methods: {
    // 选择一页显示多少数据
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
    },
    // 当前页改变时，跳转其他页面
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    reducebt(a) {
      this.$store.commit("cahnge_ShopData", a);
    },
  },
};
</script>

<style lang="less" scoped>
.bigbox {
  // position: absolute;
  width: 100%;
}
.el-table {
  // position: absolute;
  line-height: 60px;
  // top: 100px;
}
.reduce {
  width: 50px;
  height: 30px;
  border-radius: 5px 5px;
}
.add {
  width: 50px;
  height: 30px;
  border-radius: 5px 5px;
}
</style>